import axios from 'axios'
import common from './common'

const api = axios.create({
    baseURL: common.baseUrl,
    timeout: 200000,
    headers:{
        user:'60409c0056ae60584bb0b2df'
    }
});
//    封装get请求
const get = async (url, data) => {
    const response = await api.get(url, data)
        .then(res => {
            return res.data
        }).catch(error => {
            alert(error.response.data.message || '接口报错了,请重试');
        })
    return response
}

const post = async (url,data)=>{
    const response = await api.post(url,data).then(res =>{
        return res.data
    }).catch(error=>{
        handlerError(error)

    })
    return response
}
const put = async (url,data)=>{
    const response = await api.put(url,data).then(res =>{
        return res.data
    }).catch(error=>{
        handlerError(error)

    })
    return response.data
}
const del = async(url,data)=>{
    const response = await api.request({data,url,methods:'delete'}).catch(error=>{
        handlerError(error)
    })
    return response.data
}
 const handlerError = (error)=>{
    alert(error.response.data.message || '接口报错了,请重试');
}
export {
    get,
    post,
    del,
    put
}